package com.cskaoyan.app.service.impl;

import com.cskaoyan.app.bean.vo.statVo.*;
import com.cskaoyan.app.mapper.MarketOrderGoodsMapper;
import com.cskaoyan.app.mapper.MarketOrderMapper;
import com.cskaoyan.app.mapper.MarketUserMapper;
import com.cskaoyan.app.service.AdminStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Shuuka
 * @email 1712430536@qq.com
 * @date 2022/12/30 22:45
 */
@Service
public class AdminStatServiceImpl implements AdminStatService {

    @Autowired
    MarketUserMapper marketUserMapper;

    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Autowired
    MarketOrderGoodsMapper marketOrderGoodsMapper;

    @Override
    public AdminStatUserVO user() {
        AdminStatUserVO adminStatUserVO = new AdminStatUserVO();
        List<AdminStatUserRow> adminStatUserRows = marketUserMapper.userCount();
        List<String> columns = new LinkedList<>();
        for (Field declaredField : adminStatUserRows.get(0).getClass().getDeclaredFields()) {
            columns.add(declaredField.getName());
        }
        adminStatUserVO.setColumns(columns);
        adminStatUserVO.setRows(adminStatUserRows);
        return adminStatUserVO;
    }

    @Override
    public AdminStatOrderVO order() {
        AdminStatOrderVO adminStatOrderVO = new AdminStatOrderVO();
        List<AdminStatOrderRow> adminStatOrderRows = marketOrderMapper.orderCount();
        List<String> columns = new LinkedList<>();
        for (Field declaredField : adminStatOrderRows.get(0).getClass().getDeclaredFields()) {
            columns.add(declaredField.getName());
        }
        adminStatOrderVO.setColumns(columns);
        adminStatOrderVO.setRows(adminStatOrderRows);
        return adminStatOrderVO;
    }

    @Override
    public AdminStatOrderGoodsVO goods() {
        AdminStatOrderGoodsVO adminStatOrderGoodsVO = new AdminStatOrderGoodsVO();
        List<AdminStatOrderGoodsRow> adminStatOrderGoodsRows = marketOrderGoodsMapper.orderGoodsCount();
        List<String> columns = new LinkedList<>();
        for (Field declaredField : adminStatOrderGoodsRows.get(0).getClass().getDeclaredFields()) {
            columns.add(declaredField.getName());
        }
        adminStatOrderGoodsVO.setColumns(columns);
        adminStatOrderGoodsVO.setRows(adminStatOrderGoodsRows);
        return adminStatOrderGoodsVO;
    }


}
